package com.xyzyzglxt.system.service.impl;

import java.util.List;

import com.xyzyzglxt.common.core.domain.entity.SysUser;
import com.xyzyzglxt.common.core.domain.entity.SysVolunteersTime;
import com.xyzyzglxt.common.core.domain.model.LoginUser;
import com.xyzyzglxt.common.utils.SecurityUtils;
import com.xyzyzglxt.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xyzyzglxt.system.mapper.SysVolunteersTimeMapper;
import com.xyzyzglxt.system.service.ISysVolunteersTimeService;

/**
 * 【服务时长管理】Service业务层处理
 *
 * @author xyzyzglxt
 * @date 2022-03-02
 */
@Service
public class SysVolunteersTimeServiceImpl implements ISysVolunteersTimeService
{
    @Autowired
    private SysVolunteersTimeMapper sysVolunteersTimeMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询【服务时长管理】
     *
     * @param userId 【服务时长管理】主键
     * @return 【服务时长管理】
     */
    @Override
    public SysVolunteersTime selectSysVolunteersTimeByUserId(Long userId)
    {
        SysVolunteersTime sysVolunteersTime = sysVolunteersTimeMapper.selectSysVolunteersTimeByUserId(userId);
        SysUser sysUser = sysUserMapper.selectUserVoById(sysVolunteersTime.getUserId());
        sysVolunteersTime.setSysUser(sysUser);
        return sysVolunteersTime;
    }

    /**
     * 查询【服务时长管理】列表
     *
     * @param sysVolunteersTime 【服务时长管理】
     * @return 【服务时长管理】
     */
    @Override
    public List<SysVolunteersTime> selectSysVolunteersTimeList(SysVolunteersTime sysVolunteersTime)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long roleId = loginUser.getUser().getRoles().get(0).getRoleId();
        // 仅管理员可看
        if(roleId != 1){
            sysVolunteersTime.setUserId(SecurityUtils.getUserId());
        }
        List<SysVolunteersTime> sysVolunteersTimes = sysVolunteersTimeMapper.selectSysVolunteersTimeList(sysVolunteersTime);
        for (SysVolunteersTime volunteersTimeone : sysVolunteersTimes) {
            SysUser sysUser = sysUserMapper.selectUserVoById(volunteersTimeone.getUserId());
            volunteersTimeone.setSysUser(sysUser);
        }
        return sysVolunteersTimes;
    }

    /**
     * 新增【服务时长管理】
     *
     * @param sysVolunteersTime 【服务时长管理】
     * @return 结果
     */
    @Override
    public int insertSysVolunteersTime(SysVolunteersTime sysVolunteersTime)
    {
        return sysVolunteersTimeMapper.insertSysVolunteersTime(sysVolunteersTime);
    }

    /**
     * 修改【服务时长管理】
     *
     * @param sysVolunteersTime 【服务时长管理】
     * @return 结果
     */
    @Override
    public int updateSysVolunteersTime(SysVolunteersTime sysVolunteersTime)
    {
        return sysVolunteersTimeMapper.updateSysVolunteersTime(sysVolunteersTime);
    }

    /**
     * 批量删除【服务时长管理】
     *
     * @param userIds 需要删除的【服务时长管理】主键
     * @return 结果
     */
    @Override
    public int deleteSysVolunteersTimeByUserIds(Long[] userIds)
    {
        return sysVolunteersTimeMapper.deleteSysVolunteersTimeByUserIds(userIds);
    }

    /**
     * 删除【服务时长管理】信息
     *
     * @param userId 【服务时长管理】主键
     * @return 结果
     */
    @Override
    public int deleteSysVolunteersTimeByUserId(Long userId)
    {
        return sysVolunteersTimeMapper.deleteSysVolunteersTimeByUserId(userId);
    }



}

